﻿using System;
using System.Web.Helpers;

namespace User.EF.Model
{
    public partial class Member
    {
        /// <summary>
        /// Gibt den passenden Namen für den aktuellen Benutzer zurück.
        /// </summary>
        public override string ToString()
        {
            if (MemberExtension != null)
            {
                return string.Format("{0} {1}", MemberExtension.Firstname, MemberExtension.Lastname);
            }

            return Username;
        }

        /// <summary>
        /// Das aktuelle memberobjekt initialisieren.
        /// </summary>
        public void InializeCurrentMember()
        {
            Username = string.Empty;
            //Random Salt und PW anlege, wird eh überschrieben bei Bedarf.
            PasswordSalt = Crypto.GenerateSalt();
            Password = Crypto.HashPassword(Crypto.GenerateSalt());
            CreationDate = DateTime.Now;
            PasswordCheangedDate = DateTime.Now;
            PasswordVerifivationTokenExpirationDate = DateTime.Now;
            PasswordVerificationToken = string.Empty;
            LastLoginTry = DateTime.Now;
            LoginTries = 0;
            MemberExtension = new MemberExtension();
            MemberExtension.Firstname = string.Empty;
            MemberExtension.Lastname = string.Empty;
            MemberExtension.Mobilenumber = string.Empty;
            MemberExtension.Title = ETitle.None;

            MemberOAuth = new MemberOAuth();
            MemberOAuth.Provider = string.Empty;
            MemberOAuth.ProviderUserId = string.Empty;
            MemberOAuth.ProviderUsername = string.Empty;
        }
    }
}
